package com.lcl.stock.config;

import com.lcl.stock.pojo.vo.StockInfoConfig;
import com.lcl.stock.utils.IdWorker;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @ClassName CommonConfig
 * @Description TODO
 * @Author 28901
 * @Date 2025/2/23 18:03
 * @Version 1.0
 */
@Configuration
// 开启对象相关配置对象的加载
@EnableConfigurationProperties({StockInfoConfig.class})
public class CommonConfig {

    /**
     * 密码加密器
     * BCryptPasswordEncoder方法采用SHA-256对密码进行加密
     * @return
     */
    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }

    @Bean
    public IdWorker idWorker(){
        /**
         * 雪花算法生成唯一Id
         * 参数：(机器Id，机房Id)
         */
        return new IdWorker(1L,2L);
    }
}
